<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.1/axios.js"></script>
</head>

<body>
    <ul class="list">
        <li></li>
    </ul>
    <button>获取电影</button>
    <button>添加电影</button>
    <button>修改电影</button>
    <button>局部修改</button>
    <button>删除电影</button>
    <script>
        // 获取ul和按钮
        let ul = document.querySelector('ul');
        let btns = document.querySelectorAll('button');

        //获取电影列表 axios.get(url,[config]);
        btns[0].onclick = async function() {
            let data = await axios.get('http://api.zhibao.com/movies');

            console.log(data);
        }

        //添加电影  axios.post(url,[data,config])
        btns[1].onclick = async function() {
            let data = await axios.post('http://api.zhibao.com/movies', {
                name: "泰坦尼克号",
                director: "卡梅隆",
                start: "金凯+旭鹏+庞博+冯旭"
            })
            console.log(data);
        }

        // 修改电影 axios.put(url,[data,config]);
        btns[2].onclick = async function() {
            let data = await axios.put('http://api.zhibao.com/movies/12', {
                name: "三毛历险记"
            })
            console.log(data);
        }


        // 局部修改 axios.patch(url,[data,config])
        btns[3].onclick = async function() {
            let data = await axios.patch('http://api.zhibao.com/movies/10', {
                name: "大耳朵图图"
            })

            console.log(data);
        }


        // 删除电影 axios.delete(url,[config]);
        btns[4].onclick = async function() {
            let data = await axios.delete('http://api.zhibao.com/movies/12');

            console.log(data);
        }
    </script>
</body>

</html>